#include "ResultCheck.h"
#include <opencv2/opencv.hpp>
#include <string>

void ResutlCheck(const std::vector<float>& vecfx,
                 const std::vector<float>& vecfy, 
                 const std::vector<float>& coefficient)
{
    cv::Point points[vecfx.size()];
    float max_x = vecfx.back(), max_y = 0.;

    for(size_t i = 0; i < vecfx.size(); ++i){
        points[i].x = vecfx[i];
        points[i].y = vecfy[i];
        if(vecfy[i] > max_y)
            max_y = vecfy[i];
    }
    // std::cout << "max_x: " << max_x << ", max_y: " << max_y << ", coefficient.size: " 
    //             << coefficient.size() << "\n";

    // std::cout << "Construct origin points over\n";

    cv::Mat out(max_y+30, max_x+30, CV_8UC3, cv::Scalar::all(255));
    for(size_t i = 0; i < max_x; ++i){
        cv::Point2d ipt;
        ipt.x = i;
        ipt.y = 0;
        for(size_t j = 0; j < coefficient.size(); ++j)
            ipt.y += coefficient[j] * pow(i,j);
        
        cv::circle(out, ipt, 1, cv::Scalar(0, 0, 0), CV_FILLED, CV_AA);
    }
    // std::cout << "Draw fit points over\n";


    for(size_t i = 0; i < vecfx.size(); ++i)
        cv::circle(out, points[i], 3, cv::Scalar(0, 0, 255), CV_FILLED, CV_AA);
    // std::cout << "Draw origin points over\n";

    cv::imshow(std::to_string(coefficient.size()-1)+" times fit", out);
    cv::waitKey(0);
}